#include "PicturePlaybar.h"
#include "ui_PicturePlaybar.h"
#include "PictureEngine.h"


PicturePlaybar::PicturePlaybar( IF_PictureEngineInterface * engine,
                                QWidget *parent) :
   QWidget(parent),
   ui(new Ui::PicturePlaybar),
   m_engine( engine)
{
   ui->setupUi(this);

   ui->showButton->setEnabled(true);
   ui->hideButton->setEnabled(false);

   connect( ui->showButton, SIGNAL(clicked()), m_engine, SLOT(show()));
   connect( ui->hideButton, SIGNAL(clicked()), m_engine, SLOT(hide()));

   connect( m_engine, SIGNAL(currentSourceChanged(QPixmap)),
            this, SLOT(onCurrentSourceChanged(QPixmap)));

   connect( m_engine, SIGNAL(pictureShown()),
            this, SLOT(onPictureShown()));
   connect( m_engine, SIGNAL(pictureHidden()),
            this, SLOT(onPictureHidden()));
}

PicturePlaybar::~PicturePlaybar()
{
   delete ui;
}


void PicturePlaybar::onPictureShown()
{
   ui->showButton->setEnabled(false);
   ui->hideButton->setEnabled(true);
}

void PicturePlaybar::onPictureHidden()
{
   ui->showButton->setEnabled(true);
   ui->hideButton->setEnabled(false);
}

void PicturePlaybar::onCurrentSourceChanged(const QPixmap & pixmap)
{
   /* if new media is not a picture, hide viewer */
   if (pixmap.isNull())
   {
      m_engine->hide();
   }
}
